package com.dhu.graph.basic.SymbolGraph;

import com.dhu.graph.basic.edge.Edge;
import com.dhu.graph.basic.GraphImpls.EdgeWeightGraph;
import com.dhu.graph.utils.SymbolWeightedEdge;

import java.util.Set;

/**
 * @ Author ：snow
 * @ Date   ：Created in 2020-05-11
 * @ Description：
 * @ Modified By：
 * @ Version:
 */
public class EdgeWrightSymbolGraph extends SymbolGraph {

    public EdgeWrightSymbolGraph(SymbolWeightedEdge[] e){
        for (SymbolWeightedEdge edge : e) {
            String w = edge.getW();
            String v = edge.getV();
            if (!st.containsKey(v)) st.put(v, st.size());
            if (!st.containsKey(w)) st.put(w,st.size());
        }
        if (!st.isEmpty()){
            Set<String> keySet = st.keySet();
            keys = new String[st.size()];
            for (String k : keySet) {
                keys[st.get(k)] = k;
            }
            keySet = null;
            this.G = new EdgeWeightGraph(keys.length);

            for (SymbolWeightedEdge edge : e) {
                Edge ee = new Edge(index(edge.getV()), index(edge.getW()), edge.getWeight());
                this.G.addEdge(ee);
            }
        }
    }
}
